﻿using System.Collections.Generic;
using MediaLibraryManagement.DAL;
using MediaLibraryManagement.Entity;

namespace MediaLibraryManagement.BLL
{
    public class AlbumBLL
    {
        private AlbumDAL _dataAccess;
        private SongDAL _songDataAccess;

        public AlbumBLL()
        {
            _dataAccess = new AlbumDAL();
            _songDataAccess = new SongDAL();
        }

        public Album GetAlbumByID(int id)
        {
            Album album = (Album)_dataAccess.GetByID(id);
            album.Songs = _songDataAccess.GetByAlbumID(id);
            return album;
        }

        public void Insert(Album album)
        {
            int id = _dataAccess.Insert(album);
            foreach(Song song in album.Songs)
            {
                song.AlbumID = id;
            }
            _songDataAccess.Insert(album.Songs);
        }

        public void Update(Album album)
        {
            _dataAccess.Update(album);
            foreach (Song song in album.Songs)
            {
                song.AlbumID = album.ID;
            }
            _songDataAccess.DeleteByAlbumID(album.ID);
            _songDataAccess.Insert(album.Songs);
        }

        public void Delete(int id)
        {
            _dataAccess.Delete(id);
            _songDataAccess.DeleteByAlbumID(id);
        }

        public List<Album> Search(string title, string genre, string artistName, int year)
        {
            return _dataAccess.Search(title, genre, artistName, year);
        }
    }
}